package sdfi.lee.test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.sql.Connection;

import sdfi.lee.DAO.DAO;
import sdfi.lee.Properties.ReadXMLFromString;

public class gege {

	/**
	 * @param args
	 */
	public static void listFile(String path)
	{
		File file=new File(path);
//		System.out.println(path);
		if(!file.exists()) return ;
		if(file.isDirectory())
		{
			for(File f:file.listFiles())
			{
				listFile(f.getAbsolutePath());
			}
		}
		else
		{
			chile(path);
		}
	}
	public static void chile(String path)
	{
		//System.out.println(path);
		
		try
		{
		FileInputStream fis=new FileInputStream(new File(path));
		InputStreamReader isr=new InputStreamReader(fis);
		BufferedReader br=new BufferedReader(isr);
		String line=br.readLine();
		StringBuffer sb=new StringBuffer();
		while(line!=null)
		{
			sb.append(line);
			line=br.readLine();
		}
		Connection con=DAO.openSession().connection();
		ReadXMLFromString rxfs=new ReadXMLFromString();
		rxfs.setSource(sb.toString());
		
		int inty=0;
		/*
		String type=rxfs.readerValueByNode("/profile/type");
		
		if(type.equals("AchievementProfile"))
			inty=0;
		else 
		if(type.equals("MedicalDeviceProfile"))
		{
			inty=2;
		}else
		if(type.equals("MedicamentProfile"))
		{
			inty=3;
		}else
		if(type.equals("OrgProfile"))
		{
			inty=4;
		}else
		if(type.equals("DiseaseProfile"))
		{
				inty=5;
		}else
		if(type.equals("PersonProfile"))
		{
			inty=6;
		}else
		if(type.equals("PatentProfile"))
		{
			inty=7;
		}
		if(type.equals("PaperProfile"))
		{
			inty=8;
		}else
		if(type.equals("EventProfile")){
			inty=9;
		}else if(type.equals("LocationProfile"))
			inty=10;
		else if(type.equals("TimeProfile"))
			inty=11;
		else inty=-1;
		*/
		inty=-1;
		con.setAutoCommit(false);
		String sql="insert into answer(answer,path,nename,alias,documentid,type)" +
				"value('"+sb.toString()+"','"+path.replaceAll("\\\\", "/")+"','";
				sql+=rxfs.readerValueByNode("/profile/@NE")+"','"
				+rxfs.readerValueByNode("/profile/alias")
				+"','"+rxfs.readerValueByNode("/profile/@documentID")+"','"+inty+"')";
		con.createStatement().executeUpdate(sql);
		con.commit();
		System.out.println(path);
		
			}
		catch(Exception ee)
		{
			
			ee.printStackTrace();
			
			
		}
//		*/
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
//		for(int i=9;i<14;i++)
//		{
//			listFile("V:/person/"+i);
//		}
//		System.out.print("\n"+"sadf"+"\n");
		listFile("V:\\product\\");
	}

}
